<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = [
        { id: 1, name: '张三', age: 18 },
        { id: 2, name: '李四', age: 20 },
        { id: 3, name: '王五', age: 15 },
        { id: 1, name: '张三', age: 18 },
        { id: 4, name: '王五', age: 19 },
      ]
      // 数组去重 id相同  可以多个方法实现
      let arr1 = []
      arr.forEach((item,index)=>{
        arr1.indexOf(item.id)==-1?arr1.push(item.id):arr.splice(index,1)
      })
      console.log(arr);
      console.log(arr1);



      
    </script>
  </body>
</html>
